//
//  HYYHomeTitleButton.swift
//  Hyy9Weibo
//
//  Created by Air on 16/3/31.
//  Copyright © 2016年 hyy. All rights reserved.
//

import UIKit

class HYYHomeTitleButton: UIButton {
    
    //便利构造函数，调用当前类的便利构造函数
    convenience init(title:String?,imageName:String){
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        sizeToFit()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        //调整图片位置
        //1.将label移到最左边
//        var frame = self.titleLabel!.frame
//        frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
//        self.titleLabel!.frame = frame
        
        //swift可以直接设置结构体里面的成员
        titleLabel!.frame.origin.x = 0
        
        //2.将图片移到label后面
        imageView?.frame.origin.x = (titleLabel?.frame.width)!+3
    }

}
